import { request } from "@/utils/service"
import type * as Source from "./types/source"
import { AxiosResponse } from "axios"

/** 增 */
export function createSourceDataApi(data: FormData) {
  return request({
    headers: {
      "Content-Type": "multipart/form-data"
    },
    url: "/toksim/resource/raw_data/add",
    method: "post",
    data
  })
}

/** 删 */
export function deleteSourceDataApi(id: string) {
  return request({
    url: `/toksim/resource/raw_data/delete/${id}`,
    method: "post"
  })
}

/** 改 */
export function updateSourceDataApi(data: FormData) {
  return request({
    headers: {
      "Content-Type": "multipart/form-data"
    },
    url: "/toksim/resource/raw_data/edit",
    method: "post",
    data
  })
}

/** 查 */
export function getSourceDataApi(params: Source.PageTableRequestData) {
  return request<Source.SearchSourceTableResponseData>({
    url: "/toksim/resource/raw_data/search",
    method: "post",
    data: params
  })
}

/** 根据id查询资源库信息 */
export function getSourceInfoApi(id: string) {
  return request<Source.SourceViewInfoResponseData>({
    url: `/toksim/resource/raw_data/get/${id}`,
    method: "get"
  })
}
/** 获取仿真资源类型 */
export function getSourceTypeOptionsApi() {
  return request<ApiResponseData<string[]>>({
    url: `/toksim/resource/raw_data/type/get`,
    method: "get"
  })
}

/** 下载仿真资源资源 */
export function downloadSourceApi(id: string) {
  return request<AxiosResponse>({
    headers: {
      "Content-Type": "application/octet-stream"
    },
    responseType: "blob",
    url: `/toksim/resource/raw_data/download/${id}`,
    method: "get"
  })
}

export function getSourceOptionsApi() {
  return request<Source.SourceListResponseData>({
    url: "/toksim/resource/raw_data/list",
    method: "get"
  })
}
// 数据接入
export function dataAccessApi(task_id: string) {
  return request({
    url: `/toksim/resource/raw_data/${task_id}/access`,
    method: "post"
  })
}
